import logging
from datetime import timedelta
from redis import StrictRedis


class Config:
    # 从对像加载debug模式
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/db_info_15"  # 设置数据库的url
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # 不跟踪数据库变化
    REDIS_IP = '127.0.0.1'  # redis 绑定ip
    REDIS_PORT = 6379  # redis监听端口
    SESSION_TYPE = 'redis'   # 设置session存储的类型
    SESSION_REDIS = StrictRedis(host=REDIS_IP, port=REDIS_PORT)   # 设置session存储使用的redis对象
    SESSION_USE_SIGNER = True  # 开启sessionid的加密(需要使用secret_key)
    SECRET_KEY = "CjctTmYtN5Nrrt6PWlLsbD0NdUA6QIRmhW9p6CJdnw6Ku/v3kskDTc8yxVIadD3a"
    # SESSION_PERMANENT = True  # 开启session持久化
    PERMANENT_SESSION_LIFETIME = timedelta(days=7)


class DevelopConfig(Config):
    DEBUG = True
    LOG_LEVEL = logging.DEBUG


class ProductConfig(Config):
    DEBUG = False
    LOG_LEVEL = logging.ERROR


# 记录各种配置
conf = {
    'dev': DevelopConfig,
    'pro': ProductConfig
}